#include "include/operation/configurerstimulateur.h"
#include "ui_configurerstimulateur.h"

#include <QFileDialog>
#include <QDebug>

ConfigurerStimulateur::ConfigurerStimulateur(QWidget *parent) :
    QWizardPage(parent),
    ui(new Ui::ConfigurerStimulateur)
{
    setPixmap(QWizard::WatermarkPixmap, QPixmap(":/illustrations/rack"));
    ui->setupUi(this);
    registerField("stimulateur.rack*", ui->rackLineEdit);
    registerField("stimulateur.duree", ui->dureeDoubleSpinBox);
    registerField("stimulateur.auto", ui->autoCheckBox);

}

ConfigurerStimulateur::~ConfigurerStimulateur()
{
    delete ui;
}

bool ConfigurerStimulateur::isComplete() const
{
    // Le rack choisi doit être lisible par l'utilisateur.
    return QFile::exists(ui->rackLineEdit->text())
            && (QFile::permissions(ui->rackLineEdit->text()) & QFile::ReadUser);
}

void ConfigurerStimulateur::choixRack()
{
    QString rack =  QFileDialog::getOpenFileName(
                                    this,
                                    tr("Choix du Rack"),
                                    "/home",
                                    tr("Rack (*.xml)"),
                                    0,
                                    QFileDialog::ReadOnly);

    if ( !rack.isNull() )
        ui->rackLineEdit->setText(rack);
}

void ConfigurerStimulateur::changeEvent(QEvent *e)
{
    QWizardPage::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
